package com.miao.manage.web.api;

import com.miao.entity.TbItem;
import com.miao.service.TbItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 对前台访问商品信息提供的接口
 */
@RequestMapping("/api/item")
@Controller
public class ApiItemController {

    @Autowired
    private TbItemService tbItemService;

    /**
     * 根据商品ID查询商品数据
     * @param
     * @return
     */
    @RequestMapping(value = "{itemId}",method = RequestMethod.GET)
    public ResponseEntity<TbItem> queryItemById(@PathVariable("itemId")Long id){
       try{
           TbItem tbItem = tbItemService.selectById(id);
           if(null==tbItem){
               return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
           }
           return ResponseEntity.ok(tbItem);
       }catch (Exception e){
           e.printStackTrace();
       }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
